<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of powerdelegations_controller
 *
 * @author Youness.MONDIR-SC
 */
class PowerdelegationsController extends AppController {
    var $name='Powerdelegations';
function  beforeFilter() {
            parent::beforeFilter();
            $this->Auth->autoRedirect = false;
            $this->set('active',3);
        }
    function populateList($wkid=null){
        $this->layout='ajax';
        if (empty($wkid)){
            return false;
        }else{
            $this->set('PDlist',$this->Powerdelegation->getPowerdelegationByWorkflow($wkid));
        }
    }
    
    function index() {
		$this->Powerdelegation->recursive = 0;
		$this->set('powerdelegations', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid powerdelegation', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('powerdelegation', $this->Powerdelegation->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Powerdelegation->create();
			if ($this->Powerdelegation->save($this->data)) {
				$this->Session->setFlash(__('The powerdelegation has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The powerdelegation could not be saved. Please, try again.', true));
			}
		}
		$workflows = $this->Powerdelegation->Workflow->find('list');
		$users = $this->Powerdelegation->User->find('list');
		$this->set(compact('workflows', 'users'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid powerdelegation', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Powerdelegation->save($this->data)) {
				$this->Session->setFlash(__('The powerdelegation has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The powerdelegation could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Powerdelegation->read(null, $id);
		}
		$workflows = $this->Powerdelegation->Workflow->find('list');
		$users = $this->Powerdelegation->User->find('list');
		$this->set(compact('workflows', 'users'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for powerdelegation', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Powerdelegation->delete($id)) {
			$this->Session->setFlash(__('Powerdelegation deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Powerdelegation was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
    
}
?>
